<?php
namespace app\tour\model;

use think\Model;
use think\Db;
use think\Session;

class Tour extends Model
{

    /**
     * @param $id
     * @param array $field
     * @param array $where
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundExceptions
     * @throws \think\exception\DbException
     */

    static function getTourById($id,$field = array(),$where = array()){

        if(empty($field)){

            return Db::name('tours')->where($where)->where("tour_id",$id)->find();

        }else{

            $field = implode(',',$field);

            return Db::name('tours')->field($field)->where($where)->where("tour_id",$id)->find();

        }

    }


    /**
     * @param array $field
     * @param array $where
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getTourInfo($field = array(),$where = array()){

        $id = Session::get('tour_id');

        if(empty($field)){

            return Db::name('tours')->where($where)->where("tour_id",$id)->find();

        }else{

            $field = implode(',',$field);

            return Db::name('tours')->field($field)->where($where)->where("tour_id",$id)->find();

        }

    }

    static function editTourInfo($data){

        $id = Session::get('tour_id');

        return Db::name('tours')->where('tour_id',$id)->update($data);

    }
}
